import uniqueId from '@form-create/utils/lib/unique';
import {localeProps, makeOptionsRule, makeRequiredRule, makeTreeOptions} from '../../utils/index';

const label = '选择器';
const name = 'select';

export default {
  icon: 'icon-select',
  label,
  name,
  rule({t}) {
    const opt = t('props.option');
    return {
      type: name,
      field: uniqueId(),
      title: t('components.select.name'),
      info: '',
      effect: {
        fetch: ''
      },
      $required: false,
      props: {},
      options: makeTreeOptions(t('props.option'), {label: 'label', value: 'value'}, 1)
    };
  },
  props(_, {t}) {
    return localeProps(t, name + '.props', [
      makeRequiredRule(),
      makeOptionsRule(t, 'options'),
      {
        type: 'input',
        field: 'placeholder',
        title: '输入框提示文字'
      },
      {
        type: 'switch',
        field: 'multiple',
        title: '是否多选'
      },
      {
        type: 'switch',
        field: 'disabled',
        title: '是否禁用'
      },
      {
        type: 'switch',
        field: 'allowClear',
        title: '是否可以清空选项'
      },
      {
        type: 'switch',
        field: 'allowSearch',
        title: '是否可搜索'
      },
      {
        type: 'inputNumber',
        field: 'limit',
        title: '多选时最多选择的数量',
        props: {
          min: 0
        }
      },
      {
        type: 'inputNumber',
        field: 'maxTagCount',
        title: '多选时最多的显示的标签数量',
        props: {
          min: 0
        }
      }
    ])
  }
};
